from django.db import models


# Create your models here.
class UserModel(models.Model):
    uid = models.AutoField(auto_created=True, primary_key=True)
    name = models.CharField(max_length=30, unique=True, db_index=True)
    age = models.IntegerField(default=18)
    sex = models.BooleanField(default=True)
    info = models.TextField(null=True, blank=True)
    salary = models.FloatField(default=100000.345)
    money = models.DecimalField(max_digits=4, decimal_places=2)  # 10进制，最大总位数4，小数最多2位
    birthday = models.DateField(default='2000-01-01')
    lastday = models.DateField(auto_now=True)
    firstday = models.DateField(auto_now_add=True)
    file = models.FileField(null=True, blank=True, upload_to='static/uploads')
    icon = models.ImageField(null=True, blank=True, upload_to='static/uploads')
    # 其他约束
    choices = ((1, '青铜'), (2, '大师'), (3, '王者'))
    # choices(数据库存数字，管理页面显示文字),name数据库字段名,verbose_name后台管理页面显示名称
    usetype = models.IntegerField(choices=choices, default=1, name='usetype', verbose_name="用户类型")
    # editable(不可编辑,管理页面不显示该字段),db_column数据库字段名,verbose_name后台管理页面显示名称
    usetype2 = models.IntegerField(editable=False, default=1, db_column='utype2', verbose_name="用户类型2")

    def __str__(self):
        return f'{self.name}'


class PersonModel(models.Model):
    name = models.CharField(max_length=30, unique=True)
    age = models.IntegerField(default=18)

    class Meta:
        db_table = 'tb_person'  # 表名

    def __str__(self):
        return f'{self.id}-{self.name}-{self.age}'

    def __repr__(self):
        return f'{self.id}-{self.name}-{self.age}'
